home *** CD-ROM | disk | FTP | other *** search
- package kool;
-
- import com.siemens.mp.game.ExtendedImage;
- import com.siemens.mp.game.GraphicObjectManager;
- import gamelib.Font;
- import gamelib.GameAction;
- import java.util.Timer;
- import java.util.TimerTask;
- import javax.microedition.lcdui.Canvas;
- import javax.microedition.lcdui.Graphics;
- import javax.microedition.lcdui.Image;
-
- class KoolScreen extends GameScreen {
- private byte[] background = new byte[]{31, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -8, 5, 87, 119, -1, -33, 127, -38, -117, -95, 87, -5, -24, 0, 42, -86, -6, -69, -6, -12, 23, 80, 2, -1, 112, 21, 5, 85, 87, -41, 95, -48, 62, -96, 21, 127, -8, 0, 8, -118, -86, -86, -85, -128, 93, 72, 3, -1, 80, 5, 5, 85, 85, 85, 87, 64, 42, -112, 5, 95, -88, 0, 0, 8, -126, -86, -82, 0, 4, 0, 15, -81, -48, 1, 85, 85, 85, 85, 93, 0, 0, 0, 31, -9, -24, 0, 0, 40, 34, -86, -84, 0, 0, 0, -97, -9, -48, 5, 85, 85, 84, 5, 90, 0, 0, 0, 15, -41, 104, 0, 0, 2, -128, 32, 52, 0, 0, 0, -113, -10, -16, 4, 85, 85, 85, 85, 88, 0, 0, 0, 71, -41, 120, 0, 0, 0, 0, 2, -76, 2, -120, 0, -93, -89, -16, 0, 16, 17, 21, 85, 104, 23, -60, 0, 80, 79, 120, 0, 2, 0, 0, 0, 48, 47, -30, 0, 44, 31, -8, 0, 32, 1, 85, 81, 40, 31, -27, 0, 23, -3, 120, 0, 0, -128, 40, 0, 80, 62, -94, 0, 11, -2, -8, 0, 0, 21, 85, 85, 64, 125, 37, 64, 1, 85, -8, 0, 16, 0, -70, 0, 80, 62, 38, 0, 0, -86, -8, 0, 2, 85, 69, 85, 64, 61, 79, 64, 17, 85, -8, 0, 0, 10, -58, -88, 72, 26, -114, 0, -128, 43, -8, 0, 0, 85, 69, 85, 100, 15, 29, 64, 5, 87, -8, 0, 0, 0, -70, -96, 32, 32, 58, 4, 0, 43, -8, 0, 17, 20, 85, 85, 100, 16, -11, 0, 85, 95, -8, 0, 0, 2, -86, 0, 16, 10, -86, 80, 2, -85, -16, 0, 0, 20, 0, 84, 21, 65, 80, 1, 85, 127, -16, 0, 0, 0, -118, 0, 16, 0, 1, 84, 10, -81, -16, 0, 0, 64, 0, 4, 73, 64, 0, -87, 85, -1, -32, 0, 0, 2, 16, -128, 12, 0, 5, 90, -86, -65, -64, 0, 0, 0, 0, 2, 77, 64, -86, -27, 87, -1, -64, 0, 0, 0, 0, 0, 10, 0, 21, -118, 42, -1, -128, 0, 0, 0, 0, 0, 5, 98, -86, 21, -105, -1, 0, 0, 0, 0, 0, 0, 2, -48, 4, 63, -33, -2, 0, 0, 0, 0, 0, 0, 1, -22, 42, 126, -65, -4, 0, 0, 0, 0, 0, 0, 0, 53, 85, 117, 127, -8, 0, 0, 0, 0, 0, 0, 0, 10, -81, -85, -1, -32, 0, 0, 0, 0, 0, 0, 0, 7, -1, -1, -1, -64, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -2, 0, 0, 0, -128, 0, 0, 0, 0, 0, 31, -1, -16, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 3, 0, 20, 72, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 1, 0, 8, 0, 0, 0, 1, 0, 6, 0, 21, 81, 16, 16, 0, 0, 0, 0, 2, -128, 0, 0, 0, 0, 0, 0, 1, 8, 0, 0, 1, 0, 0, 0, 21, 85, 85, 68, 64, 0, -128, 0, 0, 0, 0, 0, 10, -96, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 21, 85, 85, 85, 68, 68, 16, -128, 0, 0, 0, 0, 14, -86, -86, -96, 2, 2, 4, 42, -96, 0, 0, 0, 23, -9, 85, 85, 85, 85, 81, 0, 1, 68, 16, 0, 31, -81, -21, -22, -86, -86, -86, -86, -88, 0, 0, 0, 31, -3, -1, -1, -35, -9, -41, 85, 85, 85, 85, 80, 31, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -8};
- private byte[] player_bin = new byte[]{12, 0, 13, -32, 10, -16, 26, 56, 26, 56, 25, -18, 27, 118, 62, -42, 55, -112, 56, 16, 56, 8, 103, -8, 110, -32, 110, 112, -64, -16, 0, 0, 24, 0, 25, -32, 26, -16, 26, 56, 26, 56, 25, -20, 27, 124, 62, -36, 55, -112, 56, 16, 56, 8, 55, -8, 54, -32, 46, 112, 46, -16, 0, 0, 48, 0, 49, -32, 50, -16, 50, 56, 26, 56, 25, -18, 27, 118, 30, -42, 23, -112, 24, 16, 24, 8, 31, -8, 30, 112, 30, 56, 6, 112, 0, 0, 24, 0, 25, -32, 26, -16, 26, 56, 26, 56, 25, -20, 27, 124, 62, -36, 55, -112, 56, 16, 56, 8, 55, -8, 54, 112, 46, -16, 46, 0, 0, 0, 12, 0, 13, -32, 10, -16, 26, 56, 26, 56, 25, -18, 27, 118, 62, -42, 55, -112, 56, 16, 56, 8, 103, -8, 110, -32, 110, -16, -34, -16, 0, 0, 0, 48, 7, -80, 15, 80, 28, 88, 28, 88, 119, -104, 110, -40, 107, 124, 9, -20, 8, 28, 16, 28, 31, -26, 7, 118, 14, 118, 15, 3, 0, 0, 0, 24, 7, -104, 15, 88, 28, 88, 28, 88, 55, -104, 62, -40, 59, 124, 9, -20, 8, 28, 16, 28, 31, -20, 7, 108, 14, 116, 15, 116, 0, 0, 0, 12, 7, -116, 15, 76, 28, 76, 28, 88, 119, -104, 110, -40, 107, 120, 9, -24, 8, 24, 16, 24, 31, -8, 14, 120, 28, 120, 14, 96, 0, 0, 0, 24, 7, -104, 15, 88, 28, 88, 28, 88, 55, -104, 62, -40, 59, 124, 9, -20, 8, 28, 16, 28, 31, -20, 14, 108, 15, 116, 0, 116, 0, 0, 0, 48, 7, -80, 15, 80, 28, 88, 28, 88, 119, -104, 110, -40, 107, 124, 9, -20, 8, 28, 16, 28, 31, -26, 7, 118, 15, 118, 15, 123, 0, 0};
- private byte[] player_mask = new byte[]{12, 0, 13, -32, 11, -16, 27, -8, 27, -8, 25, -18, 27, -10, 63, -10, 55, -16, 63, -16, 63, -8, 103, -8, 110, -32, 110, 112, -64, -16, 0, 0, 24, 0, 25, -32, 27, -16, 27, -8, 27, -8, 25, -20, 27, -4, 63, -4, 55, -16, 63, -16, 63, -8, 55, -8, 54, -32, 46, 112, 46, -16, 0, 0, 48, 0, 49, -32, 51, -16, 51, -8, 27, -8, 25, -18, 27, -10, 31, -10, 23, -16, 31, -16, 31, -8, 31, -8, 30, 112, 30, 56, 6, 112, 0, 0, 24, 0, 25, -32, 27, -16, 27, -8, 27, -8, 25, -20, 27, -4, 63, -4, 55, -16, 63, -16, 63, -8, 55, -8, 54, 112, 46, -16, 46, 0, 0, 0, 12, 0, 13, -32, 11, -16, 27, -8, 27, -8, 25, -18, 27, -10, 63, -10, 55, -16, 63, -16, 63, -8, 103, -8, 110, -32, 110, -16, -34, -16, 0, 0, 0, 48, 7, -80, 15, -48, 31, -40, 31, -40, 119, -104, 111, -40, 111, -4, 15, -20, 15, -4, 31, -4, 31, -26, 7, 118, 14, 118, 15, 3, 0, 0, 0, 24, 7, -104, 15, -40, 31, -40, 31, -40, 55, -104, 63, -40, 63, -4, 15, -20, 15, -4, 31, -4, 31, -20, 7, 108, 14, 116, 15, 116, 0, 0, 0, 12, 7, -116, 15, -52, 31, -52, 31, -40, 119, -104, 111, -40, 111, -8, 15, -24, 15, -8, 31, -8, 31, -8, 14, 120, 28, 120, 14, 96, 0, 0, 0, 24, 7, -104, 15, -40, 31, -40, 31, -40, 55, -104, 63, -40, 63, -4, 15, -20, 15, -4, 31, -4, 31, -20, 14, 108, 15, 116, 0, 116, 0, 0, 0, 48, 7, -80, 15, -48, 31, -40, 31, -40, 119, -104, 111, -40, 111, -4, 15, -20, 15, -4, 31, -4, 31, -26, 7, 118, 15, 118, 15, 123, 0, 0};
- private byte[] ball_L = new byte[]{-119, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 16, 0, 0, 0, 16, 8, 2, 0, 0, 0, -112, -111, 104, 54, 0, 0, 0, 6, 98, 75, 71, 68, 0, -1, 0, -1, 0, -1, -96, -67, -89, -109, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 14, -60, 0, 0, 14, -60, 1, -107, 43, 14, 27, 0, 0, 0, 72, 73, 68, 65, 84, 120, -38, 99, -8, -113, 10, 24, 48, 0, -70, 2, 76, -91, 88, -11, -93, 107, -64, 106, 24, 86, 61, 12, 120, 84, 99, 117, 30, 84, 3, 30, 69, -24, 26, -48, 89, -60, 0, 98, -52, -58, 97, 17, -83, 52, -48, 24, -112, -28, 30, -108, -120, 35, 65, 3, -111, 122, 112, 38, 62, 60, -86, 81, 52, 16, -103, -68, 1, -75, 41, -38, 38, 94, 19, -54, 110, 0, 0, 0, 0, 73, 69, 78, 68, -82, 66, 96, -126};
- private byte[] mask_L = new byte[]{-119, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 16, 0, 0, 0, 16, 8, 2, 0, 0, 0, -112, -111, 104, 54, 0, 0, 0, 6, 98, 75, 71, 68, 0, -1, 0, -1, 0, -1, -96, -67, -89, -109, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 14, -60, 0, 0, 14, -60, 1, -107, 43, 14, 27, 0, 0, 0, 50, 73, 68, 65, 84, 120, -38, 99, -8, -113, 10, 24, 48, 0, -70, 2, 60, 74, -79, 106, 99, 32, 70, 53, -78, 30, 6, 34, 85, -61, -11, -112, -82, 97, 20, 80, 61, -92, -56, -115, 56, -110, -109, 6, 57, -119, -113, -8, -28, 13, 0, -77, 101, -113, 113, 107, 39, 112, -111, 0, 0, 0, 0, 73, 69, 78, 68, -82, 66, 96, -126};
- private byte[] ball_M = new byte[]{-119, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 16, 0, 0, 0, 16, 8, 2, 0, 0, 0, -112, -111, 104, 54, 0, 0, 0, 6, 98, 75, 71, 68, 0, -1, 0, -1, 0, -1, -96, -67, -89, -109, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 14, -60, 0, 0, 14, -60, 1, -107, 43, 14, 27, 0, 0, 0, 55, 73, 68, 65, 84, 120, -38, 99, -8, 15, 3, 12, 72, -32, 63, 110, -64, -128, -84, 20, 77, 39, 62, 13, -60, -37, -125, -112, 99, -64, 6, -80, 107, -64, -91, 26, -89, 6, 60, -128, 26, 26, 72, 114, 15, -71, 26, 72, -114, 56, -110, -64, -120, -44, 0, 0, 107, -38, 34, -6, -100, 56, 80, -123, 0, 0, 0, 0, 73, 69, 78, 68, -82, 66, 96, -126};
- private byte[] mask_M = new byte[]{-119, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 16, 0, 0, 0, 16, 8, 2, 0, 0, 0, -112, -111, 104, 54, 0, 0, 0, 6, 98, 75, 71, 68, 0, -1, 0, -1, 0, -1, -96, -67, -89, -109, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 14, -60, 0, 0, 14, -60, 1, -107, 43, 14, 27, 0, 0, 0, 39, 73, 68, 65, 84, 120, -38, 99, -8, 15, 3, 12, 72, -32, 63, 110, -64, -128, -90, -108, -96, 54, -46, 53, -32, 7, 67, 67, 3, -19, 67, -119, -100, -120, 35, 9, -116, 72, 13, 0, -45, 109, 14, 15, -124, 94, -109, 7, 0, 0, 0, 0, 73, 69, 78, 68, -82, 66, 96, -126};
- private byte[] ball_S = new byte[]{-119, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 8, 0, 0, 0, 8, 8, 2, 0, 0, 0, 75, 109, 41, -36, 0, 0, 0, 6, 98, 75, 71, 68, 0, -1, 0, -1, 0, -1, -96, -67, -89, -109, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 14, -60, 0, 0, 14, -60, 1, -107, 43, 14, 27, 0, 0, 0, 33, 73, 68, 65, 84, 120, -38, 99, -8, -1, -1, 63, 3, 12, -4, 71, 2, 80, 62, -90, 28, 3, 26, 32, 66, 2, -89, 29, -1, 113, 0, -46, 37, 0, -27, 35, -125, 125, -100, -101, 70, -20, 0, 0, 0, 0, 73, 69, 78, 68, -82, 66, 96, -126};
- private byte[] mask_S = new byte[]{-119, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 8, 0, 0, 0, 8, 8, 2, 0, 0, 0, 75, 109, 41, -36, 0, 0, 0, 6, 98, 75, 71, 68, 0, -1, 0, -1, 0, -1, -96, -67, -89, -109, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 14, -60, 0, 0, 14, -60, 1, -107, 43, 14, 27, 0, 0, 0, 30, 73, 68, 65, 84, 120, -38, 99, -8, -1, -1, 63, 3, 12, -4, 71, 2, 12, 104, -128, 18, 9, -100, 118, -4, -57, 1, 72, -105, 0, 0, -23, 3, -128, -128, -12, 47, -60, 31, 0, 0, 0, 0, 73, 69, 78, 68, -82, 66, 96, -126};
- private byte[] shot_bin = new byte[]{-76, -39, 77, -108, -39, 77, -108, -39, 77, -108, -39, 77, -108, -39, 77, -108, -39, 77};
- public static final int GRAVITY = 320;
- public static final int GAMESPEED = 100;
- public static final int BALLTYPE = 0;
- public static final int BALLNUM = 1;
- public static final int BALLTYPENEW = 2;
- public static final int BALLNEWDEF = 3;
- public static final int BALLXSPEED = 0;
- public static final int BALLYSPEED = 1;
- public static final int BIGBALL = 14;
- public static final int MEDIUMBALL = 10;
- public static final int SMALLBALL = 6;
- public static final int OBSTACLEH = 1;
- public static final int OBSTACLEV = 2;
- public static final int PAUSE_MODE = -1;
- public static final int GAME_MODE = 1;
- public static final int GAMEOVER_MODE = 2;
- public static final int NEXTLEVEL_MODE = 3;
- public static final int DIE_MODE = 4;
- public static final int COLLISIONTOP = 16;
- public static final int COLLISIONLEFT = 1;
- public static final int COLLISIONRIGHT = 2;
- public static final int COLLISIONBOTTOM = 32;
- public static final int COLLISIONINSIDE = 1024;
- private static final int PRESSED = 1;
- private static final int RELEASED = 0;
- private static final int REPEATED = 1;
- private static final int GAME_SCREEN_WIDTH = 96;
- private static final int GAME_SCREEN_HEIGHT = 56;
- int[][] ballExplode = new int[][]{{14, 2, 10, 3, 100, -2, 100}, {10, 2, 6, 3, 80, -3, 80}};
- int[][][] levelBalls = new int[][][]{new int[0][], {{14, 20, 0, 1}}, {{14, 10, 0, 1}, {10, 80, 0, 3}}, {{14, 40, 0, 1}}, {{10, 10, 0, 3}, {10, 80, 0, -3}}, {{14, 20, 0, 2}, {10, 70, 0, -3}}, {{10, 10, 0, 3}, {10, 40, 0, -3}, {10, 80, 0, 3}}, {{14, 10, 0, -1}, {14, 80, 0, 1}}, {{10, 10, 0, -3}, {10, 60, 0, 3}, {10, 75, 10, -2}}, {{14, 10, 0, 1}, {10, 35, 0, -3}, {10, 80, 0, 3}}};
- int[][][] levelObstacles = new int[][][]{new int[0][], new int[0][], new int[0][], {{2, 45, 16}}, {{1, 25, 25}, {1, 35, 25}}, {{1, 17, 30}, {1, 27, 30}}, {{1, 15, 30}, {1, 70, 30}}, {{2, 45, 6}, {2, 40, 33}}, {{2, 45, 5}, {1, 65, 25}}, {{2, 40, 30}}};
- private int currentKey;
- private int currentKeyState = 0;
- private int fieldX = 0;
- private int fieldY = 0;
- public boolean bRunning;
- public boolean readyToPaint = false;
- private Image gameScreenImage;
- private ExtendedImage gameScreen = null;
- private ExtendedImage statusScreen;
- private GraphicObjectManager gfxManager;
- public Player player;
- private Ball[] balls;
- private Shoot shoot;
- private Timer timer = new Timer();
- private TimerTask counterTask;
- protected int seconds;
- private int currentLevel = 1;
- private int gameMode = -1;
- private GameAction action;
- private Obstacle[] obstacles = new Obstacle[10];
-
- public KoolScreen() {
- try {
- this.gfxManager = new GraphicObjectManager();
- this.gameScreenImage = Image.createImage(96, 56);
- this.gameScreen = new ExtendedImage(this.gameScreenImage);
- this.gameScreen.clear((byte)0);
- this.statusScreen = new ExtendedImage(Image.createImage(96, 10));
- this.statusScreen.clear((byte)0);
- Image ballS = Image.createImage(this.ball_S, 0, this.ball_S.length);
- Image ballM = Image.createImage(this.ball_M, 0, this.ball_M.length);
- Image ballL = Image.createImage(this.ball_L, 0, this.ball_L.length);
- Image maskS = Image.createImage(this.mask_S, 0, this.mask_S.length);
- Image maskM = Image.createImage(this.mask_M, 0, this.mask_M.length);
- Image maskL = Image.createImage(this.mask_L, 0, this.mask_L.length);
- this.shoot = new Shoot(1);
- this.gfxManager.addObject(this.shoot);
- this.player = new Player(this.player_bin, this.player_mask, 16, 16, 10);
- this.player.setPosition(48, 41);
- this.gfxManager.addObject(this.player);
- this.balls = new Ball[24];
-
- for(int i = 0; i < 2; ++i) {
- this.balls[i] = new Ball(0, 0, ballL, maskL, 14, 0, 0);
- this.balls[i].setVisible(false);
- this.balls[i].setCollisionRectangle(2, 2, 12, 12);
- this.gfxManager.addObject(this.balls[i]);
- }
-
- for(int i = 2; i < 8; ++i) {
- this.balls[i] = new Ball(0, 0, ballM, maskM, 10, 0, 0);
- this.balls[i].setVisible(false);
- this.balls[i].setCollisionRectangle(2, 2, 8, 8);
- this.gfxManager.addObject(this.balls[i]);
- }
-
- for(int i = 8; i < 24; ++i) {
- this.balls[i] = new Ball(0, 0, ballS, maskS, 6, 0, 0);
- this.balls[i].setVisible(false);
- this.balls[i].setCollisionRectangle(0, 0, 6, 6);
- this.gfxManager.addObject(this.balls[i]);
- }
-
- for(int i = 0; i < this.obstacles.length / 2; ++i) {
- this.obstacles[i] = new Obstacle(2);
- this.obstacles[i].setVisible(false);
- this.gfxManager.addObject(this.obstacles[i]);
- this.obstacles[i + this.obstacles.length / 2] = new Obstacle(1);
- this.obstacles[i + this.obstacles.length / 2].setVisible(false);
- this.gfxManager.addObject(this.obstacles[i + this.obstacles.length / 2]);
- }
- } catch (Exception e) {
- ((Throwable)e).printStackTrace();
- }
-
- System.gc();
- this.readyToPaint = true;
- this.startLevel();
- }
-
- private void startLevel() {
- this.player.setPosition(48, 41);
-
- for(int i = 0; i < this.levelBalls[this.currentLevel].length; ++i) {
- int ball = this.findFreeBall(this.levelBalls[this.currentLevel][i][0]);
- if (ball >= 0) {
- this.balls[ball].setPosition(this.levelBalls[this.currentLevel][i][1] + this.fieldX, this.levelBalls[this.currentLevel][i][2] + this.fieldY);
- this.balls[ball].ySpeed = 200;
- this.balls[ball].xSpeed = this.levelBalls[this.currentLevel][i][3];
- this.balls[ball].setVisible(true);
- }
- }
-
- for(int i = 0; i < this.levelObstacles[this.currentLevel].length; ++i) {
- int o = this.findFreeObstacle(this.levelObstacles[this.currentLevel][i][0]);
- if (o >= 0) {
- this.obstacles[o].setPosition(this.levelObstacles[this.currentLevel][i][1] + this.fieldX, this.levelObstacles[this.currentLevel][i][2] + this.fieldY);
- this.obstacles[o].setVisible(true);
- }
- }
-
- this.seconds = 90;
- this.timer.scheduleAtFixedRate(this.counterTask = new 1(this), 1000L, 1000L);
- this.gameMode = 1;
- }
-
- private void finishLevel() {
- for(int i = 0; i < this.balls.length; ++i) {
- this.balls[i].setVisible(false);
- }
-
- for(int i = 0; i < this.obstacles.length; ++i) {
- this.obstacles[i].setVisible(false);
- }
-
- this.counterTask.cancel();
- this.shoot.setVisible(false);
- }
-
- public void Dispose() {
- this.gameScreen = null;
- this.gfxManager = null;
- }
-
- protected void keyPressed(int keyCode) {
- int action = ((Canvas)this).getGameAction(keyCode);
- if (keyCode != 53 && action != 8) {
- if (keyCode != 52 && action != 2) {
- if (keyCode == 54 || action == 5) {
- this.currentKey = 5;
- this.currentKeyState = 1;
- }
- } else {
- this.currentKey = 2;
- this.currentKeyState = 1;
- }
- } else {
- this.addShot();
- }
-
- }
-
- protected void keyReleased(int keyCode) {
- int action = ((Canvas)this).getGameAction(keyCode);
- if (keyCode != 52 && action != 2) {
- if (keyCode == 54 || action == 5) {
- this.currentKey = 5;
- this.currentKeyState = 0;
- }
- } else {
- this.currentKey = 2;
- this.currentKeyState = 0;
- }
-
- if (keyCode == 48) {
- this.finishLevel();
- ++this.currentLevel;
- this.startLevel();
- }
-
- }
-
- protected void keyRepeated(int keyCode) {
- }
-
- private void addShot() {
- if (!this.shoot.getVisible()) {
- this.shoot.fire(this.player);
- }
-
- }
-
- private void ballExplode(int ball) {
- int n = -1;
- if (this.balls[ball].size == 14) {
- n = 0;
- } else if (this.balls[ball].size == 10) {
- n = 1;
- }
-
- Player var10000 = this.player;
- var10000.score += (n + 1) * 3;
- this.balls[ball].setVisible(false);
- if (n >= 0) {
- for(int i = 0; i < this.ballExplode[n][1]; ++i) {
- int fball = this.findFreeBall(this.ballExplode[n][2]);
- if (fball >= 0) {
- this.balls[fball].setPosition(this.balls[ball].getXPosition() - (this.ballExplode[n][3 + i * 2] < 0 ? 7 : -7), this.balls[ball].getYPosition());
- this.balls[fball].xSpeed = this.ballExplode[n][3 + i * 2 + 0];
- this.balls[fball].ySpeed = this.balls[ball].ySpeed * this.ballExplode[n][3 + i * 2 + 1] / 100;
- this.balls[fball].setVisible(true);
- }
- }
- }
-
- }
-
- private final int findFreeBall(int type) {
- for(int i = 0; i < this.balls.length; ++i) {
- if (!this.balls[i].getVisible() && this.balls[i].size == type) {
- return i;
- }
- }
-
- return -1;
- }
-
- private final int findFreeObstacle(int type) {
- for(int i = 0; i < this.obstacles.length; ++i) {
- if (this.obstacles[i].type == type && !this.obstacles[i].getVisible()) {
- return i;
- }
- }
-
- return -1;
- }
-
- public void movePlayer() {
- int dx = 0;
- if (this.currentKeyState == 1 && this.currentKey == 2) {
- dx = -this.player.speed;
- } else if (this.currentKeyState == 1 && this.currentKey == 5) {
- dx = this.player.speed;
- }
-
- if (this.player.getXPosition() + dx - 1 < 81 && this.player.getXPosition() + dx >= this.fieldX) {
- this.player.setPosition(this.player.getXPosition() + dx, this.player.getYPosition());
- if (dx < 0 && this.player.orientation != 0) {
- this.player.setOrientation(0);
- }
-
- if (dx > 0 && this.player.orientation != 5) {
- this.player.setOrientation(5);
- }
-
- if (dx != 0) {
- this.player.animate();
- }
-
- }
- }
-
- public synchronized void moveObjects() {
- int width = 96;
- int height = 56;
- if (this.shoot.getVisible()) {
- this.shoot.move();
- }
-
- int xc = 0;
- int yc = 0;
- if (this.shoot.getVisible()) {
- for(int i = 0; i < this.balls.length; ++i) {
- if (this.balls[i].getVisible() && this.shoot.isCollidingWith(this.balls[i])) {
- this.ballExplode(i);
- }
- }
- }
-
- int ballCount = 0;
-
- for(int i = 0; i < this.balls.length; ++i) {
- if (this.balls[i].getVisible()) {
- ++ballCount;
-
- for(int o = 0; o < this.obstacles.length; ++o) {
- if (this.obstacles[o].getVisible()) {
- int[] obs = this.obstacles[o].getCollisionRectangle();
- int c = this.ballCollision(this.balls[i].getXPosition(), this.balls[i].getYPosition(), this.balls[i].size, obs);
- if ((c & 16) != 0) {
- if (this.balls[i].ySpeed > 0) {
- Ball var10000 = this.balls[i];
- var10000.ySpeed *= -1;
- }
- } else if ((c & 32) != 0 && this.balls[i].ySpeed < 0) {
- Ball var11 = this.balls[i];
- var11.ySpeed *= -1;
- }
-
- if ((c & 1) != 0) {
- if (this.balls[i].xSpeed > 0) {
- Ball var12 = this.balls[i];
- var12.xSpeed *= -1;
- }
- } else if ((c & 2) != 0 && this.balls[i].xSpeed < 0) {
- Ball var13 = this.balls[i];
- var13.xSpeed *= -1;
- }
- }
- }
-
- if (this.balls[i].getXPosition() + this.balls[i].xSpeed >= width - this.balls[i].size + this.fieldX) {
- this.balls[i].setPosition(width - this.balls[i].size + this.fieldX, this.balls[i].getYPosition());
- this.balls[i].xSpeed = -this.balls[i].xSpeed;
- } else if (this.balls[i].getXPosition() + this.balls[i].xSpeed <= this.fieldX) {
- this.balls[i].setPosition(this.fieldX, this.balls[i].getYPosition());
- this.balls[i].xSpeed = -this.balls[i].xSpeed;
- } else {
- this.balls[i].setPosition(this.balls[i].getXPosition() + this.balls[i].xSpeed, this.balls[i].getYPosition());
- }
-
- this.balls[i].ySpeed += 320;
- this.balls[i].setPosition(this.balls[i].getXPosition(), this.balls[i].getYPosition() + this.balls[i].ySpeed / 1000);
- if (this.balls[i].getYPosition() >= height + this.fieldY - this.balls[i].size) {
- this.balls[i].setPosition(this.balls[i].getXPosition(), height + this.fieldY - this.balls[i].size);
- this.balls[i].ySpeed = -this.balls[i].ySpeed;
- }
-
- if (this.balls[i].isCollidingWith(this.player)) {
- this.action = new 2(this);
- return;
- }
- }
- }
-
- if (ballCount == 0) {
- this.gameMode = 3;
- }
-
- }
-
- private final int ballCollision(int bx, int by, int r, int[] shape) {
- bx += r / 2;
- by += r / 2;
- int where = 0;
- int testX = bx;
- int testY = by;
- int br = r / 2 * (r / 2);
- if (bx < shape[0]) {
- testX = shape[0];
- where |= 1;
- } else if (bx > shape[0] + shape[2]) {
- testX = shape[0] + shape[2];
- where |= 2;
- }
-
- if (by < shape[1]) {
- testY = shape[1];
- where |= 16;
- } else if (by > shape[1] + shape[3]) {
- testY = shape[1] + shape[3];
- where |= 32;
- }
-
- return this.dist(bx, by, testX, testY) <= br ? where : 0;
- }
-
- private final int dist(int x1, int y1, int x2, int y2) {
- return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
- }
-
- public void paint(Graphics g) {
- if (this.gameScreen != null && this.readyToPaint) {
- this.gameScreen.blitToScreen(0, 13);
- }
-
- }
-
- public int getReturnValue() {
- return 0;
- }
-
- public void run() {
- this.bRunning = true;
-
- while(this.bRunning) {
- try {
- Graphics g = this.gameScreen.getImage().getGraphics();
- g.setClip(0, 0, 96, 56);
- switch (this.gameMode) {
- case 2:
- Thread.yield();
- g.setColor(16777215);
- g.fillRect(4, 4, 88, 48);
- g.setColor(0);
- g.drawRect(4, 4, 88, 48);
- g.drawString("Game Over!", 18, 15, 20);
- Font.drawString(g, "you scored: ".concat(String.valueOf(String.valueOf(this.player.score))), 13, 36);
- this.gameScreen.blitToScreen(0, 13);
- Thread.sleep(4000L);
- this.bRunning = false;
- break;
- case 3:
- Thread.yield();
- this.finishLevel();
- g.setColor(16777215);
- g.fillRect(4, 4, 88, 48);
- g.setColor(0);
- g.drawRect(4, 4, 88, 48);
- g.drawString("Well done!", 20, 9, 20);
- Font.drawString(g, "level bonus:", 9, 28);
- Font.drawString(g, "time bonus:", 9, 36);
- int levelBonus = this.currentLevel * 20;
- int timeBonus = this.seconds;
- Font.drawString(g, Integer.toString(levelBonus), 57, 28);
- Font.drawString(g, Integer.toString(timeBonus), 57, 36);
- Player var7 = this.player;
- var7.score += levelBonus + timeBonus;
- this.gameScreen.blitToScreen(0, 13);
- var7 = this.player;
- var7.score += 250;
- ++this.currentLevel;
- Thread.sleep(3500L);
- this.startLevel();
- break;
- case 4:
- Thread.yield();
- --this.player.lives;
- if (this.player.lives <= 0) {
- this.gameMode = 2;
- } else {
- g.setColor(16777215);
- g.fillRect(4, 4, 88, 48);
- g.setColor(0);
- g.drawRect(4, 4, 88, 48);
- g.drawString(String.valueOf(String.valueOf((new StringBuffer(String.valueOf(String.valueOf(this.player.lives)))).append(this.player.lives == 1 ? " life" : " lives").append(" left!"))), 18, 20, 20);
- this.gameScreen.blitToScreen(0, 13);
- Thread.sleep(2000L);
- this.finishLevel();
- this.startLevel();
- }
- }
-
- Thread.yield();
- } catch (Exception var5) {
- }
-
- if (this.gameMode == 1) {
- if (this.action != null) {
- this.action.performAction();
- if (this.action.isOver()) {
- this.action = null;
- }
- } else {
- this.moveObjects();
- this.movePlayer();
- }
- }
-
- try {
- this.gameScreen.setPixels(this.background, 0, 0, 96, 56);
- this.gfxManager.paint(this.gameScreen, 0, 0);
- this.statusScreen.clear((byte)0);
- this.statusScreen.getImage().getGraphics().drawString("Score:".concat(String.valueOf(String.valueOf(this.player.score))), 0, 0, 20);
- String s = String.valueOf(String.valueOf((new StringBuffer(String.valueOf(String.valueOf(this.seconds / 60)))).append(":").append(this.seconds % 60 < 10 ? "0" : "").append(this.seconds % 60)));
- this.statusScreen.getImage().getGraphics().drawString(s, 71, 0, 20);
- this.gameScreen.blitToScreen(0, 13);
- this.statusScreen.blitToScreen(0, 0);
- } catch (Exception e) {
- ((Throwable)e).printStackTrace();
- }
- }
-
- }
-
- // $FF: synthetic method
- static int access$0(KoolScreen x$0, int x$1) {
- return x$0.gameMode = x$1;
- }
- }
-